package zlog

import (
    "fmt"
    "io"
    "os"
    "time"
)

const (
    colon = ":"
    slash = "/"
)

// writers 获取句柄
func writers(name string) io.Writer {
    if writer, has := zlog.writers.Load(name); has {
        return writer.(io.Writer)
    }

    path := fmt.Sprintf("%s/%s.log", zlog.config.Dir, name)
    file, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
    if err == nil {
        zlog.writers.Store(name, file)
        _, _ = file.Write([]byte("\n" + time.Now().Format("2006-01-02 15:04:05.000000") + "  初始化日志句柄" + "\t" + name))

        return file
    }

    panic(any(fmt.Sprintf("日志:%s句柄获取失败[%s]", name, err.Error())))
}
